<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<script>
    // first = '00:32'
    // second = '02:16'
    // diff = getSecondsBetween(first,second)
    // document.write("<h2>first="+first+"</h2>")
    // document.write("<h2>second="+second+"</h2>")
    // document.write("<h2>diff="+diff+"</h2>")

    let firstReadyTime = null
    let firstAnswerTime = undefined
    let secondReadyTime = 0 / 0


    // firstReadyTime = MistakeToZero(firstReadyTime)
    // firstAnswerTime = MistakeToZero(firstAnswerTime)
    // secondReadyTime = MistakeToZero(secondReadyTime)
    //
    // document.write("<h2>firstReadyTime="
    //     + firstReadyTime + "</h2>")
    // document.write("<h2>firstAnswerTime="
    //     + firstAnswerTime + "</h2>")
    // document.write("<h2>secondReadyTime="
    //     + secondReadyTime + "</h2>")

    // firstReadyTime = 65
    // firstReadyTime = formatSeconds(firstReadyTime)
    // document.write("<h2>firstReadyTime="
    //     + firstReadyTime + "</h2>")
    //
    // secondReadyTime = 180
    // secondReadyTime = formatSeconds(secondReadyTime)
    // document.write("<h2>secondReadyTime="
    //     + secondReadyTime + "</h2>")
    //
    // firstReadyTime = 201
    // firstReadyTime = formatSeconds(firstReadyTime)
    // document.write("<h2>firstReadyTime="
    //     + firstReadyTime + "</h2>")

    let fileName = '0927下午_市政建设_全.mp3'
    let fileNameNoPostfix = fileNameTrim(fileName);
    document.write("<h2>fileNameNoPostfix="
        + fileNameNoPostfix + "</h2>")


    fileName = '0927下午_市政建设__全_.txt'
    fileNameNoPostfix = fileNameTrim(fileName);
    document.write("<h2>fileNameNoPostfix="
        + fileNameNoPostfix + "</h2>")


    //对文件名进行裁剪
    //如 '0927下午_市政建设_全.mp3' -> '0927下午_市政建设'
    function fileNameTrim(fileName) {
        let fileNameNoPostfix = fileName.substring(0, fileName.lastIndexOf("."))
        let reg = RegExp(/._全$/g);
        if (fileNameNoPostfix.match(reg)) {
            fileNameNoPostfix = fileNameNoPostfix.substring(0,fileNameNoPostfix.length-2)
        }
        return fileNameNoPostfix
    }

    //错误值：NaN、null和undefined转0
    function MistakeToZero(obj) {
        if (!obj) {
            obj = 0
        }
        return obj
    }


    //计算时间差之间有多少秒
    //如 00:32 和 02:16之间相差104秒
    function getSecondsBetween(first, second) {
        let ret = '0'
        let firstMin = parseInt(first.substring(0, 2))
        let firstSeconds = parseInt(first.substring(3))

        let secondMin = parseInt(second.substring(0, 2))
        let secondSeconds = parseInt(second.substring(3))

        let totalSeconds = (secondMin - firstMin) * 60 + (secondSeconds - firstSeconds)

        ret = parseInt(totalSeconds)
        return ret
    }


    //将秒数转换为时分秒格式
    function formatSeconds(value) {
        var theTime = parseInt(value);// 秒

        if (theTime === 0) {
            return '0秒钟'
        }

        var middle = 0;// 分
        var hour = 0;// 小时

        if (theTime > 60) {
            middle = parseInt(theTime / 60);
            theTime = parseInt(theTime % 60);
            if (middle > 60) {
                hour = parseInt(middle / 60);
                middle = parseInt(middle % 60);
            }
        }
        let theTimeNum = parseInt(theTime)
        // 出现 1分5秒 前补零为 1分05秒
        let result = "" + (Array(2).join(0) + theTimeNum).slice(-2) + "秒";
        if (theTimeNum === 0) {
            result = "钟"
        }
        if (middle > 0) {
            result = "" + parseInt(middle) + "分" + result;
        }
        if (hour > 0) {
            result = "" + parseInt(hour) + "小时" + result;
        }
        return result;
    }
</script>

</body>
</html>